package com.jcl.recruit.resume.provider;

import com.jcl.recruit.mapper.provider.SqlProvider;
import com.jcl.recruit.resume.model.ResumeEdu;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

public class ResumeEduSqlProvider implements SqlProvider<ResumeEdu> {

    private static final String TABLE_NAME = "resume_edu";

    public String insert(ResumeEdu record) {
        BEGIN();
        INSERT_INTO(TABLE_NAME);
        
        if (record.getResumeId() != null) {
            VALUES("resume_id", "#{resumeId,jdbcType=INTEGER}");
        }
        if (record.getCorpCode() != null) {
            VALUES("corp_code", "#{corpCode,jdbcType=VARCHAR}");
        }

        if (record.getSchool() != null) {
            VALUES("school", "#{school,jdbcType=VARCHAR}");
        }
        
        if (record.getMajor() != null) {
            VALUES("major", "#{major,jdbcType=VARCHAR}");
        }
        
        if (record.getDegree() != null) {
            VALUES("degree", "#{degree,jdbcType=VARCHAR}");
        }
        
        if (record.getStartDate() != null) {
            VALUES("start_date", "#{startDate,jdbcType=VARCHAR}");
        }
        
        if (record.getEndDate() != null) {
            VALUES("end_date", "#{endDate,jdbcType=VARCHAR}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKey(ResumeEdu record) {
        BEGIN();
        UPDATE(TABLE_NAME);
        
        if (record.getResumeId() != null) {
            SET("resume_id = #{resumeId,jdbcType=INTEGER}");
        }
        
        if (record.getSchool() != null) {
            SET("school = #{school,jdbcType=VARCHAR}");
        }
        
        if (record.getMajor() != null) {
            SET("major = #{major,jdbcType=VARCHAR}");
        }
        
        if (record.getDegree() != null) {
            SET("degree = #{degree,jdbcType=VARCHAR}");
        }
        
        if (record.getStartDate() != null) {
            SET("start_date = #{startDate,jdbcType=VARCHAR}");
        }
        
        if (record.getEndDate() != null) {
            SET("end_date = #{endDate,jdbcType=VARCHAR}");
        }
        
        WHERE("id = #{id,jdbcType=INTEGER}");
        
        return SQL();
    }
}